package com.twinkle.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @title: WebMvcConfig
 * @description:
 * @author: Paul
 * @date: 2023/2/20 9:03
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Value("${data.image.path}")
    private String pictureSavePath;

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/file/**").addResourceLocations("file:" + pictureSavePath);
        registry.addResourceHandler("/pdf/**").addResourceLocations("file:" + pictureSavePath);
    }

//    @Bean//使用@Bean注入fastJsonHttpMessageConvert
//    public HttpMessageConverter fastJsonHttpMessageConverters(){
//        //1.需要定义一个Convert转换消息的对象
//        FastJsonHttpMessageConverter fastConverter=new FastJsonHttpMessageConverter();
//        //2.添加fastjson的配置信息，比如是否要格式化返回的json数据
////
//        FastJsonConfig fastJsonConfig=new FastJsonConfig();
//        fastJsonConfig.setSerializerFeatures(SerializerFeature.PrettyFormat);
//        fastJsonConfig.setDateFormat("yyyy-MM-dd HH:mm:ss");
//        //3.在convert中添加配置信息
//        fastConverter.setFastJsonConfig(fastJsonConfig);
//        HttpMessageConverter<?> converter=fastConverter;
//        return converter;
//    }
//
//    /**
//     * 添加自定义转换器
//     * @param converters
//     */
//    @Override
//    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
////        FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter();
////        FastJsonConfig config = new FastJsonConfig();
////        config.setSerializerFeatures(SerializerFeature.WriteMapNullValue);//保留空字段
////        config.setDateFormat("yyyy-MM-dd HH:mm:ss");
////        converter.setFastJsonConfig(config);
////        converter.setDefaultCharset(Charset.forName("UTF-8"));
////        converter.setSupportedMediaTypes(Arrays.asList(MediaType.APPLICATION_JSON_UTF8));
////        converters.add(converter);
//        converters.add(fastJsonHttpMessageConverters());
//    }

}